/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author MTI
 */
@Entity
@Table(name = "ORDERPRODUCTS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Orderproducts.findAll", query = "SELECT o FROM Orderproducts o"),
    @NamedQuery(name = "Orderproducts.findById", query = "SELECT o FROM Orderproducts o WHERE o.id = :id"),
    @NamedQuery(name = "Orderproducts.findLastId", query = "SELECT c.id FROM Orderproducts c order by c.id desc"),
    @NamedQuery(name = "Orderproducts.findByPrice", query = "SELECT o FROM Orderproducts o WHERE o.price = :price"),
    @NamedQuery(name = "Orderproducts.findByOrderdate", query = "SELECT o FROM Orderproducts o WHERE o.orderdate = :orderdate"),
    @NamedQuery(name = "Orderproducts.findBestSellers", query = "SELECT o.productid.id as urunid,o.productid.name as productname,count(o.productid.id) AS ordercount FROM Orderproducts o GROUP BY o.productid.id,o.productid.name")})
public class Orderproducts implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID")
    private Integer id;
    @Column(name = "PRICE")
    private Integer price;
    @Column(name = "ORDERDATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date orderdate;
    @JoinColumn(name = "PRODUCTID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Products productid;
    @JoinColumn(name = "ORDERID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Orders orderid;

    public Orderproducts() {
    }

    public Orderproducts(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    public Date getOrderdate() {
        return orderdate;
    }

    public void setOrderdate(Date orderdate) {
        this.orderdate = orderdate;
    }

    public Products getProductid() {
        return productid;
    }

    public void setProductid(Products productid) {
        this.productid = productid;
    }

    public Orders getOrderid() {
        return orderid;
    }

    public void setOrderid(Orders orderid) {
        this.orderid = orderid;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Orderproducts)) {
            return false;
        }
        Orderproducts other = (Orderproducts) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Model.Orderproducts[ id=" + id + " ]";
    }
}
